<template>
  <div>
    <!-- 表单 -->
    <div class="table_content">
      <el-table :data="logData" style="width: 100%">
        <!-- 序号 -->
        <el-table-column type="index" label="序号" align="center">
        </el-table-column>
        <!-- 访问人真事姓名 -->
        <el-table-column prop="realname" label="访问人真事姓名" align="center">
        </el-table-column>
        <!-- 访问方式 -->
        <el-table-column prop="method" label="访问方式" align="center">
        </el-table-column>
        <!-- 访问路径 -->
        <el-table-column prop="content" label="访问路径" align="center">
        </el-table-column>
        <!-- 访问时间 -->
        <el-table-column prop="logTime" label="访问时间" align="center">
          <template slot-scope="scope">
            <div>
              {{ scope.row.logTime | reallyTime }}
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="paginetion">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[3, 6, 9, 12]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { get } from "@/utils/request";
import moment from "moment";

export default {
  data() {
    return {
      //日志数据
      logData: [],
      //当前页
      currentPage: 1,
      //每页包含多少数据
      pageSize: 12,
      //页数总数据
      total: 10,
      //时间转换
      trueTime: "",
    };
  },
  filters: {
    reallyTime: function (date) {
      return moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
  },
  computed: {},
  methods: {
    async getAllLogData() {
      let data = {
        page: this.currentPage,
        pageSize: this.pageSize,
      };
      let res = await get("/baseLog/pageQuery", data);
      // console.log(res);
      this.logData = res.data.list;
      this.total = res.data.total;
    },
    //控制每页数据条数
    //val 每页要展示的数据条数
    handleSizeChange(val) {
      //每页数据条数更新
      this.pageSize = val;
      // console.log(`每页 ${val} 条`);
      //将当前的页数重置到第一页
      this.currentPage = 1;
      this.getAllLogData();
    },
    //控制当前页面是第几页
    //val 当前页码
    handleCurrentChange(val) {
      //将当前页数与分页插件动态绑定
      this.currentPage = val;
      // console.log(`当前页: ${val}`);
      //重新调用获取产品数据的方式
      this.getAllLogData();
    },
  },
  created() {
    this.getAllLogData();
  },
  mounted() {},
};
</script>
<style scoped>
.paginetion {
  margin-top: 10px;
  text-align: right;
}
</style>